<!DOCTYPE html>
<html lang="en" style="width:100%">
<head>
    <meta charset="UTF-8">
<!--    <name>图层配置</name>-->
    <script src="../../lib/jquery/jquery-3.5.1.min.js"></script>
    <link href="../../component/layui/css/layui.css" rel="stylesheet" />
    <link href="../../admin/css/pearCommon.css" rel="stylesheet" />
    <link href="./layerConfig.css" rel="stylesheet" />
    <style type="text/css">


    </style>
</head>
<body style="width:100%;overflow: hidden;">
<div id="head">
    <div style="color: white;font-size: 26px;margin-left: 35px;height:50px; line-height:50px; "> 图层管理</div>
</div>
<div id="content">
    <div id="left">
            <div id="list_item1">
                <a class="one_left" id="logo_layer"><img src="img/layer.png " style="position: relative; width:30px;margin:10px;"></a>
            </div>
    </div>

    <div id="c" style=" display: flex;">
            <iframe class="" id="layer_iframe" name="container" src="../../previewLayer.html"  style="position: relative;width:100%;height:100%;border: none;margin-left: 50px;"></iframe>
        <div id="layer">
            <div id="layer_item1">
                <span style="position: relative; width:30px;margin-left:20px; font-size: 18px;">图层配置</span>
                <a class="logo_close" id="logo_close"><img src="img/mini.png " style="position: relative; width:30px;margin-left:150px;background-color:gray"></a>
                <hr style="height:1px;border:none;border-top:1px gray;" />
            </div>
            <div id="layer_item2">
                <div id="tree">
                    <fieldset class="layui-elem-field layui-field-name" style="margin-top: 10px;">
                        <a class="layer_add" id="layer_add"><img src="img/add.png " style="position: relative; width:20px;float:left; "></a>
<!--                        <a class="layer_add" id="layer_delete"><img src="img/delete.png " style="position: relative; width:20px;float:right;"></a>-->
                        <legend>图层</legend>
                    </fieldset>
                </div>
                <div class="demo-tree" id="treeLi">
                </div>
            </div>
        </div>
    </div>
</div>
<div class="site-text" id="service-window" style="margin: 5%; display: none"  target="test123">
    <form class="layui-form" id="service-add">
        <div class="layui-form-item">
            <label class="layui-form-label">图层名称</label>
            <div class="layui-input-block">
                <input autocomplete="off" class="layui-input" id="feature-name" lay-verify="required"  name="title" placeholder="请输入图层名称" required type="text">
                <div class="layui-form-mid layui-word-aux">必填项</div>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">图层描述</label>
            <div class="layui-input-block">
                <textarea class="layui-textarea" id="feature-detail" name="desc" placeholder="请输入图层描述"></textarea>
            </div>
        </div>

        <div class="layui-form-item" id="research">
            <hr/>
            <label class="layui-form-label">要素名称    </label>
            <div class="layui-input-inline">
                <input class="layui-input" id="demoReload"  name="elementName" placeholder="" type="text">
            </div>
            <a class="pear-btn pear-btn-md pear-btn-primary" data-type="reload" id="featureSearch" lay-filter="user-query" lay-submit>
                <i class="layui-icon layui-icon-search"></i>
                查询
            </a>
<!--            <button type="reset" class="pear-btn pear-btn-md">
                <i class="layui-icon layui-icon-refresh"></i>
                重置
            </button>-->
        </div>
        <div class="layui-form-item">
            <div class="layui-card">
                <div class="layui-card-body" id="user" >
                    <table id="user-table" lay-filter="user-table"></table>
                </div>
            </div>
        </div>
    </form>

</div>
<script id="data-type" type="text/html">
    {{#if (d.type == 1) { }}
    <span>自定义要素</span>
    {{# }else if(d.type == 2){ }}
    <span>远程服务要素</span>
    {{# }else if(d.type == 3){ }}
    <span>业务要素</span>
    {{# }else if(d.type == 4){ }}
    <span>空间模型要素</span>
    {{# } }}
</script>
<script src="../../component/layui/layui.js"></script>
<script src="./layerConfig.js"></script>
<script>
    var layerConfigObj = {};
    var featureId;
    var checkedType;
    layui.use(['tree', 'util','table','form'], function(){
        let table = layui.table;
        let form = layui.form;
        var tree = layui.tree
            ,layer = layui.layer
            ,util = layui.util
            //模拟数据2
            ,data2 = [{
                title: '早餐'
                ,id: 1
                ,children: [{
                    title: '油条'
                    ,id: 5
                },{
                    title: '包子'
                    ,id: 6
                },{
                    title: '豆浆'
                    ,id: 7
                }]
            },{
                title: '午餐'
                ,id: 2
                ,checked: true
                ,children: [{
                    title: '藜蒿炒腊肉'
                    ,id: 8
                },{
                    title: '西湖醋鱼'
                    ,id: 9
                },{
                    title: '小白菜'
                    ,id: 10
                },{
                    title: '海带排骨汤'
                    ,id: 11
                }]
            },{
                title: '晚餐'
                ,id: 3
                ,children: [{
                    title: '红烧肉'
                    ,id: 12
                    ,fixed: true
                },{
                    title: '番茄炒蛋'
                    ,id: 13
                }]
            },{
                title: '夜宵'
                ,id: 4
                ,spread: true
                ,children: [{
                    title: '小龙虾'
                    ,id: 14
                    ,checked: true
                },{
                    title: '香辣蟹'
                    ,id: 15
                    ,disabled: true
                },{
                    title: '烤鱿鱼'
                    ,id: 16
                }]
            }];
        //启用图层
        layerConfigObj.start = function(data,checkedType){
            data.checked=checkedType;
            // console.log(data);
            var child=[];
            if(data.children&&data.children.length==0 ){
                layer.msg("图层文件夹不存在图层，请添加后再启用", {icon: 5});
            }else if((data.children&&data.isDir=="1") || (data.children&&data.children.length>0)){
                function loop(item) {
                    console.log(item);
                    $.ajax({
                        url: "/back/layer",
                        type: "PUT",
                        dataType: "json",
                        contentType: "application/json; charset=UTF-8",
                        data:JSON.stringify({
                            elementId:item.elementId,
                            id:item.id,
                            isDir:item.isDir,
                            parentId: item.parentId,
                            layerName: item.title,
                            remark:item.remark,
                            sort:item.sort,
                            status:1
                        }),
                        success: function(result){
                            if(result.errorCode==0){
                                layer.msg("启用图层成功", {icon: 6});
                            }else{
                                layer.msg("启用图层失败，请检查图层对应的要素内容是否为空", {icon: 5});
                            }
                        }
                    });
                }
                child=data.children;
                child.forEach(item=>loop(item));

            }else {
                $.ajax({
                    url: "/back/layer",
                    type: "PUT",
                    dataType: "json",
                    contentType: "application/json; charset=UTF-8",
                    data:JSON.stringify({
                        elementId:data.elementId,
                        id:data.id,
                        isDir:data.isDir,
                        parentId: data.parentId,
                        layerName: data.title,
                        remark:data.remark,
                        sort:data.sort,
                        status:data.checked?1:0
                    }),
                    success: function(result){
                        if(result.errorCode==0){
                            layer.msg("启用图层成功", {icon: 6});
                            // console.log(result.status);
                            // tree.reload('treeId', {data: getData()});
                        }else{
                            layer.msg("启用图层失败，请检查图层对应的要素内容是否为空", {icon: 5});
                        }
                    }
                });
            }
        };
        //禁用图层
        layerConfigObj.close = function(data,checkedType){
            data.checked=checkedType;
            var child=[];
            if(data.children&&data.children.length==0 ){
                layer.msg("图层文件夹不存在图层，请添加后再禁用", {icon: 5});
            }else if((data.children&&data.isDir=="1") || (data.children&&data.children.length>0)){
                // debugger
                function loop(item) {
                    console.log(item);
                    $.ajax({
                        url: "/back/layer",
                        type: "PUT",
                        dataType: "json",
                        contentType: "application/json; charset=UTF-8",
                        data:JSON.stringify({
                            elementId:item.elementId,
                            id:item.id,
                            isDir:item.isDir,
                            parentId: item.parentId,
                            layerName: item.title,
                            remark:item.remark,
                            sort:item.sort,
                            status:0
                        }),
                        success: function(result){
                            if(result.errorCode==0){
                                layer.msg("禁用图层成功", {icon: 6});
                            }else{
                                layer.msg("禁用图层失败", {icon: 5});
                            }
                        }
                    });
                }
                child=data.children;
                child.forEach(item=>loop(item));

            }else {
                $.ajax({
                    url: "/back/layer",
                    type: "PUT",
                    dataType: "json",
                    contentType: "application/json; charset=UTF-8",
                    data:JSON.stringify({
                        elementId:data.elementId,
                        id:data.id,
                        isDir:data.isDir,
                        parentId: data.parentId,
                        layerName: data.title,
                        remark:data.remark,
                        sort:data.sort,
                        status:data.checked?1:0
                    }),
                    success: function(result){
                        console.log(result);
                        if(result.errorCode==0){
                            layer.msg("禁用图层成功", {icon: 6});
                            // data.status = 0;
                            // console.log(result);
                        }else{
                            layer.msg("禁用图层失败，请检查图层对应的要素内容是否为空", {icon: 5});
                        }
                    }
                });
            }
        };
        var dataT = [];
        function getData(){
            // var data = [];
            $.ajax({
                url: '/back/layer/tree',
                dataType:'json',
                type:'get',
                async:false,
                success: function(result){
                    var treeData=result.data;
                    var stringTree=JSON.stringify(treeData);
                    var dataStr=stringTree.replace(/layerName/g,"title");
                    var dataS = dataStr.replace(/status/g,"checked");
                    dataT= JSON.parse(dataS);

                    function loop(item) {
                        if(item.children && item.children.length>0){
                            delete item.checked;
                            for(var i=0;i<item.children.length;i++){
                                loop(item.children[i])
                            }
                        }else if(item.children && item.children.length==0){
                            delete item.checked;
                        }
                        else{
                            item.checked=item.checked=="1"?true:false;
                        }
                    }
                    dataT.forEach(item=>loop(item))
                }
            });
            // dataT[0].spread=true;
            // console.log(dataT);
            return dataT;
        }

        tree.render({
            elem: '#treeLi'
            ,data: getData()
            // ,data: data2
            ,id: 'treeId'
            ,showCheckbox: true  //是否显示复选框
            ,onlyIconControl: true//控制点击父节点的title子节点不收缩，点击图标时进行收缩
            // ,customOperate: true //自定义设置树操作
            ,limitNodeAddLevel:2 //设置第X级节点不允许添加操作
            ,limitNodeDelLevel:1 //设置第X级节点不允许删除操作
            // ,skin: 'shihuang'
            ,showLine:false //是否开启连接线。默认 true，若设为 false，则节点左侧出现三角图标。
            ,edit: ['add', 'update', 'del','moveup','movedown'] //操作节点的图标
            ,isJump: true //是否允许点击节点时弹出新窗口跳转
            ,click: function(obj){
                console.log(obj);
                var checkType = obj.data.checked;
                // console.log(checkType);
                if(obj.data.isDir==="1"){
                    layer.msg("图层文件夹不可预览", {icon: 5});
                }else{
                    if(checkType === true){
                        layerConfigObj.preview(obj);
                    }
                    else if(checkType === false){
                        layer.msg("禁用状态不可预览，请先启用图层", {icon: 5});
                    }
                }
            }
            ,oncheck: function (obj){
                checkedType = obj.checked;
                var data = obj.data;
                // console.log(obj);
                if(checkedType === false){ //关闭节点
                    // layerConfigObj.preview(obj);
                    layerConfigObj.close(data,checkedType);
                }
                else if(checkedType === true){ //启用节点
                    layerConfigObj.start(data,checkedType);
                    // layerConfigObj.previewClose(obj);
                }
            }
            ,operate: function(obj){
                // console.log(obj);
                var type = obj.type; //得到操作类型：add、edit、del、moveup、movedown
                var data = obj.data; //得到当前节点的数据
                // var elem = obj.elem;//得到当前节点元素
                var deptId = data.id;//得到节点索引
                if(type === 'add'){ //增加节点
                    layerConfigObj.add(data);
                }
                else if(type === 'update'){ //修改节点
                    layerConfigObj.update(data);
                }
                else if(type === 'del'){ //删除节点
                    layerConfigObj.del(data);
                }
                else if(type === 'moveup'){ //上移节点
                    // console.log(data);
                    layerConfigObj.moveup(data);
                }
                else if(type === 'movedown'){ //下移节点
                    layerConfigObj.movedown(data);
                }
            }
        });

        //执行节点勾选
        // tree.setChecked('treeId', 1); //单个勾选 id 为 1 的节点
        // tree.setChecked('treeId', [9,26]); //批量勾选 id 为 2、3 的节点
        //获得选中的节点
        // var checkData = tree.getChecked('treeId');
        // console.log(checkData);
        let cols = [
            [
                {type:'checkbox',align:'center'},
                {title: '要素名称', field: 'elementName', align:'center', width:300},
                {title: '要素类别', field: 'type', align:'center', templet:'#data-type', width:300}
            ]
        ];


        table.render({
            elem: '#user-table',
            url: '/back/element/list',
            method: 'post',
            contentType: 'application/json',
            where: {status:"1"},
            request: {
                pageName: 'pageNo' //页码的参数名称，默认：page
                ,limitName: 'pageSize' //每页数据量的参数名，默认：limit
            },
            parseData: function(res){ //res 即为原始返回的数据
                return {
                    "createTime": null,
                    "createBy": null,
                    "updateTime": null,
                    "updateBy": null,
                    "remark": null,
                    "code": 200,
                    "msg": "...",
                    "count": res.data.total,
                    "data":res.data.list
                }
            },
            id: 'user-table',
            page: true ,
            cols: cols ,
            skin: 'line',
            // even: true,//开启隔行背景
            response: {
                statusCode: 200 //成功的状态码，默认：0
            },
        });
        //图层添加时复选框状态判断
        table.on('checkbox(user-table)', function(obj){
            featureId=obj.data.id;
            // console.log(obj.checked); //当前是否选中状态
            // console.log(obj.data); //选中行的相关数据
            // console.log(obj.type); //如果触发的是全选，则为：all，如果触发的是单选，则为：one
            // console.log(table.checkStatus('user-table').data); // 获取表格中选中行的数据
        });
 /*       //按钮事件
        util.event('user-table', {
            getChecked: function(othis){
                var checkedData = tree.getChecked('treeId'); //获取选中节点的数据
                layer.alert(JSON.stringify(checkedData), {shade:0});
                console.log(checkedData);
            }
        });*/

        //上移图层
        layerConfigObj.moveup = function(data){
            var upId=data.id;
            var forTree = function(arr, id) {
                for (var i = 0; i < arr.length; i++) {
                    var item = arr[i];
                    var itemUp =arr[i-1];
                    if (item.id === id) {
                        item.sort = item.sort - 1;
                        itemUp.sort = itemUp.sort + 1;
                        $.ajax({
                            url: "/back/layer",
                            type: "PUT",
                            dataType: "json",
                            contentType: "application/json; charset=UTF-8",
                            data:JSON.stringify({
                                elementId:item.elementId,
                                id:item.id,
                                isDir:item.isDir,
                                parentId: item.parentId,
                                layerName: item.title,
                                remark:item.remark,
                                sort:item.sort,
                                status:item.checked?1:0
                            }),
                        });
                        $.ajax({
                            url: "/back/layer",
                            type: "PUT",
                            dataType: "json",
                            contentType: "application/json; charset=UTF-8",
                            data:JSON.stringify({
                                elementId:itemUp.elementId,
                                id:itemUp.id,
                                isDir:itemUp.isDir,
                                parentId: itemUp.parentId,
                                layerName: itemUp.title,
                                remark:itemUp.remark,
                                sort:itemUp.sort,
                                status:itemUp.checked?1:0
                            }),
                            success: function(result){
                                console.log(result);
                                if(result.errorCode==0){
                                    layer.msg("上移图层成功", {icon: 6});
                                    var treeData = openTree(getData(),data.id);
                                    tree.reload('treeId', {data: treeData});
                                }else{
                                    layer.msg("上移图层失败", {icon: 5});
                                }
                            }
                        });
                        break
                    } else {
                        if (item.children) {
                            forTree(item.children, id);
                        }
                    }
                }
                return arr;
            };
            forTree(dataT,upId);
        };
        // ..树展开
        var openTree = function(treeData, objId) {
            var nodeId = familyTree(treeData, objId);
            function each(data) {
                try{
                    data.forEach(e => {
                        if (nodeId.indexOf(e.id) != -1) {
                            e.spread = true;
                        }
                        if (e.children.length > 0) {
                            each(e.children);
                        }
                    })
                }catch(e){
                   console.log(1);
                }
            }
            each(treeData);
            return treeData;
        };
        // 查找一个节点的所有父节点
        var familyTree = function(arr1, id) {
            var temp = [];
            var forFn = function(arr, id) {
                for (var i = 0; i < arr.length; i++) {
                    var item = arr[i];
                    // console.log(item);
                    if (item.id === id) {
                        temp.push(item.id);
                        forFn(arr1, item.parentId);
                        break
                    } else {
                        if (item.children) {
                            forFn(item.children, id);
                        }
                    }
                }
            };
            forFn(arr1, id);
            return temp;
        };
        //下移图层
        layerConfigObj.movedown = function(data){
            var downId=data.id;
            var forTree = function(arr, id) {
                for (var i = 0; i < arr.length; i++) {
                    var item = arr[i];
                    var itemDown = arr[i+1];
                    if (item.id === id) {
                        item.sort = item.sort + 1;
                        itemDown.sort = itemDown.sort - 1;
                        $.ajax({
                            url: "/back/layer",
                            type: "PUT",
                            dataType: "json",
                            contentType: "application/json; charset=UTF-8",
                            data:JSON.stringify({
                                elementId:item.elementId,
                                id:item.id,
                                isDir:item.isDir,
                                parentId: item.parentId,
                                layerName: item.title,
                                remark:item.remark,
                                sort:item.sort,
                                status:item.checked?1:0
                            }),
                        });
                        $.ajax({
                            url: "/back/layer",
                            type: "PUT",
                            dataType: "json",
                            contentType: "application/json; charset=UTF-8",
                            data:JSON.stringify({
                                elementId:itemDown.elementId,
                                id:itemDown.id,
                                isDir:itemDown.isDir,
                                parentId: itemDown.parentId,
                                layerName: itemDown.title,
                                remark:itemDown.remark,
                                sort:itemDown.sort,
                                status:itemDown.checked?1:0
                            }),
                            success: function(result){
                                console.log(result);
                                if(result.errorCode==0){
                                    layer.msg("上移图层成功", {icon: 6});
                                    var treeData = openTree(getData(),data.id);
                                    tree.reload('treeId', {data: treeData});
                                }else{
                                    layer.msg("上移图层失败", {icon: 5});
                                }
                            }
                        });
                        break
                    } else {
                        if (item.children) {
                            forTree(item.children, id);
                        }
                    }
                }
                return arr;
            };
            forTree(dataT,downId);
        };
        //图层预览
        layerConfigObj.preview = function(obj){
            // var checkedType = obj.checked;
            // console.log(obj.data);
            var data = obj.data;
            $.ajax({
                url: "/back/layer/elementInfo",
                type: "GET",
                dataType: "json",
                contentType: "application/json; charset=UTF-8",
                data:{id:data.id},
                success: function(result){
                    if(result.errorCode==0){
                        var previewUrl=result.data.elementContent;
                        console.log(previewUrl);
                        var JUMP_PATH = "/jump.html";
                        var jumpUrl="";
                        // 判断添加的服务地址是否为geoserver发布的服务
                        if(previewUrl.indexOf("geoserver") != -1 ){
                            jumpUrl =  JUMP_PATH + '?url='+ previewUrl.substr(previewUrl.indexOf("geoserver")-1)+'&type='+result.data.serviceType;//jumpUrl通过geoserver截断解决跨域问题
                        } else if(previewUrl.indexOf("geoserver") == -1 ){
                            jumpUrl =  JUMP_PATH + '?url='+ previewUrl+'&type='+result.data.serviceType;//jumpUrl字符串中不含有geoserver字符串
                        }
                        //更改iframe内容
                        $("#layer_iframe").attr("src",jumpUrl);
                        // window.open(jumpUrl);
                    /*    var JUMP_PATH = "/previewLayer.html";
                        var previewUrlValue= JSON.stringify(previewUrl);
                        sessionStorage.previewUrl=previewUrlValue;
                        window.open(JUMP_PATH);
                        // location.href=JUMP_PATH;*/
                    }else{
                        if(data.isDir==1){
                            layer.msg("图层文件夹不支持预览", {icon: 5});
                        }else if(data.isDir==0){
                            console.log(data.isDir);
                            layer.msg("图层预览失败，请检查图层对应的要素内容是否为空", {icon: 5});
                        }
                    }
                }
            });
        };
        //关闭图层预览
        layerConfigObj.previewClose = function(obj){
            // var checkedType = obj.checked;
            // console.log(obj.data);
            var data = obj.data;
            $.ajax({
                url: "/back/layer/elementInfo",
                type: "GET",
                dataType: "json",
                contentType: "application/json; charset=UTF-8",
                data:{id:data.id},
                success: function(result){
                    if(result.errorCode==0){
                        // debugger
                        var previewUrl=result.data.elementContent;
                        console.log(previewUrl);
                        var JUMP_PATH = "/jump.html";
                        var jumpUrl="";
                        // 判断添加的服务地址是否为geoserver发布的服务
                        if(previewUrl.indexOf("geoserver") != -1 ){
                            jumpUrl =  JUMP_PATH + '?url='+ previewUrl.substr(previewUrl.indexOf("geoserver")-1)+'&type='+result.data.serviceType;//jumpUrl通过geoserver截断解决跨域问题
                        } else if(previewUrl.indexOf("geoserver") == -1 ){
                            jumpUrl =  JUMP_PATH + '?url='+ previewUrl+'&type='+result.data.serviceType;//jumpUrl字符串中不含有geoserver字符串
                        }
                        $("#layer_iframe").attr("src",jumpUrl);
                        // window.open(jumpUrl);
                        /*    var JUMP_PATH = "/previewLayer.html";
                            var previewUrlValue= JSON.stringify(previewUrl);
                            sessionStorage.previewUrl=previewUrlValue;
                            window.open(JUMP_PATH);
                            // location.href=JUMP_PATH;*/
                    }else{
                        if(data.isDir==1){
                            layer.msg("图层文件夹不支持预览", {icon: 5});
                        }else if(data.isDir==0){
                            console.log(data.isDir);
                            layer.msg("图层预览失败，请检查图层对应的要素内容是否为空", {icon: 5});
                        }
                    }
                }
            });
        };
        //添加图层
        layerConfigObj.add = function(data){
            layer.open({
                type: 1,
                title: '添加图层',
                shade: 0.1,
                area: ['50%', '90%'],
                content: $('#service-window'),
                resize: true,
                btn: ['确定', '取消'],
                success:function(layero,index){
                    $('#feature-name').show();
                    $('#feature-detail').show();
                    $('#user').show();
                    $('#research').show();
                },
                yes:function(index,layero){
                    $.ajax({
                        url: "/back/layer",
                        type: "POST",
                        dataType: "json",
                        contentType: "application/json; charset=UTF-8",
                        data:JSON.stringify({
                            elementId:featureId,
                            isDir:'0',
                            parentId: data.id,
                            layerName: $('#feature-name').val(),
                            remark:$('#feature-detail').val(),
                            sort:0,
                            status:1
                        }),
                        success: function(result){
                            if(result.errorCode==0){
                                layer.msg("增加成功", {icon: 6}, function(i){
                                    layer.close(i);
                                    layer.close(index);//关闭弹出层
                                });
                                var treeData = openTree(getData(),data.id);
                                tree.reload('treeId', {data: treeData});
                            }else{
                                layer.msg("添加失败", {icon: 5});
                            }
                        }
                    });
                }
            });
        };

        $('#featureSearch').on('click', function(){
            var active = {
                reload: function(){
                    var demoReload = $('#demoReload');
                    //执行重载
                    table.reload('user-table', {
                        page: {
                            curr: 1 //重新从第 1 页开始
                        }
                        ,where: {
                            elementName: demoReload.val()
                        }
                    }, 'data');
                }
            };
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });
        layerConfigObj.update = function(data){
            $.ajax({
                url: "/back/layer",
                type: "PUT",
                dataType: "json",
                contentType: "application/json; charset=UTF-8",
                data:JSON.stringify({
                    elementId:data.elementId,
                    id:data.id,
                    isDir:data.isDir,
                    parentId: data.parentId,
                    layerName: data.title,
                    remark:data.remark,
                    sort:data.sort,
                    status:data.status
                }),
                success: function(result){
                    if(result.errorCode==0){
                        layer.msg("修改成功", {icon: 6});
                    }else{
                        layer.msg("修改失败", {icon: 5});
                    }
                }
            });
        };
        layerConfigObj.del = function(data){
            var idn = data.id;
            var arr = new Array(); //创建了一个长度为0的数组对象。
            arr.push(idn);
            // console.log(arr);
            $.ajax({
                url: "/back/layer?"+"id="+arr.join("&id="),
                type: "DELETE",
                dataType: "json",
                contentType: "application/json; charset=UTF-8",
                success: function(result){
                    if(result.errorCode==0){
                        layer.msg("删除成功", {icon: 6});
                    }else{
                        layer.msg("删除失败", {icon: 5});
                    }
                }
            });

        };

        //添加图层文件夹
        $('#layer_add').on('click', function(){
            layer.open({
                type: 1,
                title: '添加图层文件夹',
                shade: 0.1,
                area: ['50%', '50%'],
                content: $('#service-window'),
                resize: true,
                btn: ['确定', '取消'],
                success:function(layero,index){
                    $('#feature-name').show();
                    $('#feature-detail').show();
                    $('#user').hide();
                    $('#research').hide();
                },
                yes:function(index,layero){
                    $.ajax({
                        url: "/back/layer",
                        type: "POST",
                        data:JSON.stringify({
                            layerName: $('#feature-name').val(),
                            parentId:0,
                            isDir: 1,
                            sort: 0,
                            remark: $('#feature-detail').val(),
                            status: 1
                        }),
                        dataType: "json",
                        contentType: "application/json; charset=UTF-8",
                        success: function(result){
                            console.log(result);
                            if(result.errorCode==0){
                                layer.msg("增加成功", {icon: 6},function(i){
                                    layer.close(i);
                                    layer.close(index);//关闭弹出层
                                });
                                tree.reload('treeId', {data: getData()});
                            }else{
                                layer.msg("添加失败", {icon: 5});
                            }
                        }
                    });
                }
            });
        });

    });
</script>
</body>

</html>

